extends Node

const BASIC_DAMAGE = 10#伤害

@export var axe_ability_scene: PackedScene
@onready var timer = $Timer

var damage_percetn: float = 1.0#伤害百分比


func _ready() -> void:
	timer.timeout.connect(on_timer_timeout)
	self.get_parent().axe_upgrade.connect(on_upgrade)
	pass

#冷却结束时，生成一个斧子
func on_timer_timeout() -> void:
	var player = get_tree().get_first_node_in_group("player") as Node2D
	if player == null:
		return
		
	var foreground = self.get_tree().get_first_node_in_group("foreground_layer")
	if foreground == null:
		return
	var axe_ability_instance = axe_ability_scene.instantiate() as Node2D
	foreground.add_child(axe_ability_instance)
	axe_ability_instance.global_position = player.global_position
	axe_ability_instance.hit_box_componcent.damage = BASIC_DAMAGE * damage_percetn
	pass

#升级时增加斧子的伤害
func on_upgrade(upgrade: AbilityUpgrade, current_upgrade: Dictionary) -> void:
	if upgrade.id == "axe_damage":
		damage_percetn = 1 + current_upgrade[upgrade.id]["quantity"] * .1
	pass
